package controllers;

import models.User;
import play.mvc.Before;
import play.mvc.Controller;
import play.mvc.With;

@With(Secure.class)
public class Admin extends Controller {

	/**
	 * This method is responsible for the login, if the user was connected
	 * successfully, it renders his username in his homepage and puts his id in
	 * the session  
	 */
	@Before
	static void setConnectedUser() {
		if (Security.isConnected() && User.count() != 0) {
			User user = User.find("userName", Security.connected()).first();
			renderArgs.put("user", user.userName);
			session.put("userId", user.getEntityId());
			
			if(Registration.regStatus) Users.addUserToProject();
			
			Registration.registered = false;
			render("Application/index.html");
			
		}
	}

	/**
	 * This method renders the homepage
	 */
	public static void index() {
		
	}

}
